'''
''' Override DataBind(),call mybase Databind() to populate the UI
''' controls using the DataSource and then initilize the values of
''' field control
'''
Public Overrides Sub DataBind()
'Call MyBase.DataBind()
MyBase.DataBind()
If (Not Me.Page.IsPostBack) Then
' Get the key from the URL.
Dim keyFromUrl As String = me.Page.Request.QueryString("Initfrom${Table Name}")
' keyFromUrl variable will contain a parameter string as follows
' InitfromEmployees=4 or InitfromEmployees=<...xml parameter definition...>
' set this url for New button in a page with table control.
If Not IsNothing(keyFromUrl) AndAlso (Trim(keyFromUrl).Length > 0) Then
' Create the where clause.
Dim wc As WhereClause = new WhereClause()
Dim recId As String = keyFromUrl
If (KeyValue.IsXmlKey(recId)) Then
' Key are typically passed as XML structures to handle composite keys.
' If XML, then add a Where clause based on the Primary Key in the XML.
Dim pkValue As KeyValue = KeyValue.XmlToKey(recId)
wc.iAND(${${Table Name}ClassName}.${Primary Key}, BaseFilter.ComparisonOperator.EqualsTo, pkValue.GetColumnValue(${${Table Name}ClassName}.${Primary Key}).ToString())
Else
' The URL parameter contains the actual value, not an XML structure.
wc.iAND(${${Table Name}ClassName}.${Primary Key}, BaseFilter.ComparisonOperator.EqualsTo, recId)
End If
' Get existing record based on primary key.
Dim rec As ${${Table Name}RecordClassName}() = ${${Table Name}ClassName}.GetRecords(wc, Nothing, 0, 2)
If (rec.Length > 0) Then
' Populate each field value based on existing record's values.
Me.${Initialization Field Control}.Text = rec(0).${Initialization Field}.ToString()
End If
End If
End If
End Sub
|